#ifndef _ConteneurCode
#define _ConteneurCode
#include <string>
#include "string.h"
#include <vector>
#include "Instruction.hpp"

using std::vector;

class ConteneurCode{
public:	
	ConteneurCode() {};
	~ConteneurCode() {};

	static ConteneurCode* ConcatCont(ConteneurCode* c1,ConteneurCode* c2) {
		
		ConteneurCode * c = new ConteneurCode();
		
		vector<Instruction>::iterator it;
		
		for ( vector<Instruction>::iterator it = c1->listeInstr.begin(); it!=c1->listeInstr.end(); ++it ){
    			c->ajouterInstruction (&(*it));
		}
		
		vector<Instruction>::iterator it2;
		
		for ( vector<Instruction>::iterator it2 = c2->listeInstr.begin(); it2!=c2->listeInstr.end(); ++it2 ){
    			c->ajouterInstruction (&(*it2));
		}
		
		
		return c;
	};
	
	void ajouterInstruction(Instruction* i) {
		listeInstr.push_back(*i); 	
	};
  
  Instruction getLastVarAff(char * nomvar)
  {
    
    for (int i = listeInstr.size()-1; i >= 0; i--)
    {
      char * idOpG = listeInstr[i].getOp1().getOpAsCharEt();
      
      if (strcmp(idOpG,nomvar) == 0)
      {
        listeInstr[i].afficherInstr();
        return listeInstr[i];
      }
    }
    return Instruction();
  }
	
	
	void afficher() {
		vector<Instruction>::iterator it;
		cout << "AFFICHAGE DU CODE 3@" << endl;
		for ( vector<Instruction>::iterator it = listeInstr.begin(); it!=listeInstr.end(); ++it ){
    			(*it).afficherInstr();
		}
	};
	
	void setResultat(Operande o1) {
		o=o1;
	}
	
	Operande getResultat() {
		return(o);
	}
	
private:
	vector<Instruction> listeInstr;
	Operande o;
};
#endif
